package com.example.zz.example.java.synchronizedtest;

/**
 * @author: zhuozhang6
 * @date: 2022/5/26
 * @email: zhuozhang6@iflytek.com
 * @Description:
 */
public class Something {
    public synchronized void isSyncA() {
    }

    public synchronized void isSyncB() {
    }

    public static synchronized void cSyncA() {
    }

    public static synchronized void cSyncB() {
    }


    //方法锁，核心是对象锁，等同于下面的add2对象锁
    public synchronized void add() {
        System.out.println("add");
    }

    //对象锁一，与上面的方法锁
    public void add2() {
        synchronized (this) {
            System.out.println("add2");
        }
    }

    Object o = new Object();

    //对象锁二
    public void add3() {
        synchronized (o) {
            System.out.println("add3");
        }
    }

    //类锁一
    public void add4() {
        synchronized (Something.class) {
            System.out.println("add4");
        }
    }

    //类锁二，和类锁一一样
    public synchronized static void add5() {
        System.out.println("add5");
    }
}
